﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Media;

namespace Microsoft.Windows.UserControls
{
    public class WizardButton : ImageButton
    {
        const String PropertyCommandType = "CommandType";
        
        #region Dependency Properties

        public static readonly DependencyProperty CommandTypeProperty = DependencyProperty.Register(PropertyCommandType, typeof(ButtonCommandType), typeof(WizardButton), new UIPropertyMetadata(ButtonCommandType.None, OnButtonCommandTypeChanged));

        #endregion
        
        #region Properties
            
        public ButtonCommandType CommandType
        {
            get
            {
                return (ButtonCommandType)base.GetValue(CommandTypeProperty);
            }
            set
            {
                base.SetValue(CommandTypeProperty, value);
            }
        }
      
        #endregion
        
        #region ctor
        
        static WizardButton()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(WizardButton), new FrameworkPropertyMetadata(typeof(WizardButton)));
        }

        public WizardButton()
        {
        }

        #endregion
        
        #region Static Methods
            
        static void OnButtonCommandTypeChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
        {
            var control = (sender as WizardButton);
            if (control == null)
                return;
        
            control.OnCommandTypeChanged((ButtonCommandType)args.NewValue);
        }

        #endregion

        #region Overrides
        
        protected override void OnCultureUIChanged(CultureInfo cultureInfo)
        {
            base.OnCultureUIChanged(cultureInfo);
            OnCommandTypeChanged(CommandType);
        }
        
        #endregion

        #region Methods
        
        protected virtual void OnCommandTypeChanged(ButtonCommandType commandType)
        {
            switch (commandType)
            {
                case ButtonCommandType.Help:
                    ImageData = Geometry.Parse(Properties.ImageDataResources.WizardButton_Help);
                    Content = Properties.Resources.WizardButtonComandText_Help;
                    Command = Core.Commands.WizardCommands.Help;
                    break;
                case ButtonCommandType.Cancel:
                    ImageData = Geometry.Parse(Properties.ImageDataResources.WizardButton_Cancel);
                    Content = Properties.Resources.WizardButtonComandText_Cancel;
                    Command = Core.Commands.WizardCommands.Cancel;
                    break;
                case ButtonCommandType.Previous:
                    ImageData = Geometry.Parse(Properties.ImageDataResources.WizardButton_Previous);
                    Content = Properties.Resources.WizardButtonComandText_Previous;
                    Command = Core.Commands.WizardCommands.Previous;
                    break;
                case ButtonCommandType.Next:
                    ImageData = Geometry.Parse(Properties.ImageDataResources.WizardButton_Next);
                    Content = Properties.Resources.WizardButtonComandText_Next;
                    Command = Core.Commands.WizardCommands.Next;
                    break;
                case ButtonCommandType.Finish:
                    ImageData = Geometry.Parse(Properties.ImageDataResources.WizardButton_Finish);
                    Content = Properties.Resources.WizardButtonComandText_Finish;
                    Command = Core.Commands.WizardCommands.Finish;
                    break;
                default:
                    break;
            }
        }
       
        #endregion
        
        public enum ButtonCommandType
        {
            None,
            Help,
            Cancel,
            Previous,
            Next,
            Finish
        }
    }
}